package com.lagou.demo.consumer;


import com.lagou.demo.constant.OrderStatus;
import com.lagou.demo.dao.OrderDao;
import com.lagou.demo.pojo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class OrderConsumer {

    @Autowired
    OrderDao orderDao;


    /**
     * 用户超时未支付
     */
    @RabbitListener(queues = "dlx_queue")
    public void timeoutOrderMessage(@Payload String message) {

        log.info("接收到用户的超时未支付订单,订单号为:{}", message);
        //将订单的状态修改为超时未支付
        orderDao.updateOrderStatusById(message, OrderStatus.CANCELLED_OVER_TIME);
        log.info("订单号为:{}的订单状态修改为超时未支付", message);

        //查询用户所有付款超时而取消的订单
        List<Order> overTimeOrder = orderDao.getOrderByStatus(OrderStatus.CANCELLED_OVER_TIME);
        log.info("用户所有付款超时而取消的订单为:{}", overTimeOrder);
    }
}
